package com.studyyoun.demoandroidapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.dart.DartExecutor;

public class MainActivity extends AppCompatActivity {
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		TextView openFlutterTextView = findViewById(R.id.bt_main_open_1);
		
		openFlutterTextView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(MainActivity.this, OpenFlutterActivity.class));
			}
		});
		
		
		TextView flutterMessateTextView = findViewById(R.id.bt_main_flutter_message);
		
		flutterMessateTextView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(MainActivity.this, FlutterMessageActivity.class));
			}
		});

		TextView flutterViewTextView = findViewById(R.id.bt_main_flutter_view);

		flutterViewTextView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(MainActivity.this, FlutterViewActivity.class));
			}
		});

		//创建引擎
		FlutterEngine lFlutterEngine = new FlutterEngine(this);
		//设置一些参数 如初始加载显示的路由页面
		lFlutterEngine.getNavigationChannel().setInitialRoute("/test");
		//设置缓存
		lFlutterEngine.getDartExecutor()
				.executeDartEntrypoint(DartExecutor.DartEntrypoint.createDefault());
		//put引擎
		FlutterEngineCache.getInstance().put("test_engine2", lFlutterEngine);

		
	}
	
	
}